import axios from 'axios'
import {getToken} from "@/util/auth";

const service = axios.create({
    baseURL: 'http://geek.itheima.net/v1_0',
    timeout: 5000
})

service.interceptors.request.use(
    config => {
        const token = getToken()
        if (token) config.headers.Authorization = `Bearer ${token}`
        return config
    },
    error => {
        console.dir(error)
        return Promise.reject(error)
    }
)

service.interceptors.response.use(
    response => {
        return response.data
    },
    error => {
        console.dir(error)
        return Promise.reject(error)
    }
)

export default service
